<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test11</title>
    <link rel="stylesheet" type="text/css" href="css/css_11.css">
</head>
<body>
<h1 style="text-align: center">HTML复习历程-11</h1>
<div class="slideshow-container">
    <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
        <img src="https://c.runoob.com/wp-content/uploads/2017/01/img_mountains_wide.jpg" style="width:100%">
        <div class="text">文本 1</div>
    </div>

    <div class="mySlides fade">
        <div class="numbertext">2 / 3</div>
        <img src="https://c.runoob.com/wp-content/uploads/2017/01/img_fjords_wide.jpg" style="width:100%">
        <div class="text">文本 2</div>
    </div>

    <div class="mySlides fade">
        <div class="numbertext">3 / 3</div>
        <img src="https://c.runoob.com/wp-content/uploads/2017/01/img_nature_wide.jpg" style="width:100%">
        <div class="text">文本 3</div>
    </div>

</div>
<div style="text-align:center">
    <span class="dot" onclick="changePot(3)"></span>
    <span class="dot" onclick="changePot(1)"></span>
    <span class="dot" onclick="changePot(2)"></span>
</div>
<script>
    var slideIndex = 0;
    setInterval(function () {
        showSlides();
    }, 2000)
    showSlides();


    function showSlides() {
        var i;
        var slides = document.getElementsByClassName("mySlides");
        var dots = document.getElementsByClassName("dot");
        for (i = 0; i < slides.length; i++) {
            slides[i].style.display = "none";
        }
        console.log("now:"+slideIndex)
        slideIndex++;
        if (slideIndex > slides.length) {slideIndex = 1}
        for (i = 0; i < dots.length; i++) {
            dots[i].className = dots[i].className.replace(" active", "");
        }
        slides[slideIndex-1].style.display = "block";
        dots[slideIndex-1].className += " active";
        // setTimeout(showSlides, 3000); // 切换时间为 2 秒
    }

    function changePot(tag) {
        if (tag<1){
            return
        }
        slideIndex = tag
        showSlides()
    }
</script>
<br>
</body>
</html>
